package com.wakaka.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.wakaka.pojo.Dept;
import com.wakaka.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//提供Rest ful服务
@RestController
public class DeptController {

    @Autowired
    IDeptService service;

    @RequestMapping("/get/{id}")
    @HystrixCommand(fallbackMethod = "hyxtrixGet")
    public Dept get(@PathVariable("id") long id) {
        Dept dept = service.queryById(id);
        if (dept == null) {
            throw new RuntimeException("没有找到对应信息");
        }
        return dept;
    }

    // 备选方案
    public Dept hyxtrixGet(@PathVariable("id") long id) {
        return new Dept().setId(1).setName("该用户信息不存在");
    }
}
